﻿#ifndef __LUA_CONVERTOR_H__
#define __LUA_CONVERTOR_H__

#include "./defaultconvertor.h"

struct LuaConvertor
{
public:
	inline void SetLuaState(lua_State* luaState)
	{
		m_luaState = luaState;
	}
    inline void Init(int* pParamIndex)
    {
        m_pParamIndex = pParamIndex;
    }
protected:
    template <typename T>
    inline T GetValue()
    {
        return (T)getvalue<T>(m_luaState, (*m_pParamIndex)++);
    }
    template <typename T>
    inline void SetValue(T val)
    {
        setvalue<T>(m_luaState, val);
    }
protected:
    lua_State* m_luaState;
    int* m_pParamIndex;
};

template <class T>
struct TypeConvertor : public LuaConvertor
{
public:
    inline T InitValue()
    {
        return 0;
    }
    inline T GetValue()
    {
        return LuaConvertor::GetValue<T>();
    }
    inline int SetValue(T val)
    {
        LuaConvertor::SetValue(val);
        return 1;   //return one value
    }
};

template <>
struct TypeConvertor<void> : public LuaConvertor
{
public:
    inline void SetValue(void)
    {
    }
};

#endif